package com.mall.user.domain.service;

import com.mall.goods.common.helper.AdminSessionHelper;
import com.mall.goods.common.helper.ShopHelper;
import com.mall.goods.common.repository.LogRepository;
import com.mall.user.domain.mapper.AdminLogMapper;
import com.mall.user.domain.model.AdminLog;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

/**
 * 日志仓储实现类
 * @author yangfei
 */
@Slf4j
@Repository
public class LogRepositoryImpl implements LogRepository {
    @Resource
    private AdminLogMapper adminLogMapper;




    @Override
    public void log(String content, String ip) {
        int adminId=0;
        String adminName="";
        try{
            adminId= AdminSessionHelper.getAdminId();
            adminName=AdminSessionHelper.getAdminName();
        }catch (Exception e){
            e.printStackTrace();
            log.info("Admin操作日志记录，商家信息获取失败");
        }
        AdminLog adminLog = new AdminLog();
        adminLog.setAdminId(adminId);
        adminLog.setAdminName(adminName);
        adminLog.setContent(content);
        adminLog.setCreateTime(ShopHelper.getCurrentTimestamp());
        adminLog.setIp(ip);
        adminLogMapper.insert(adminLog);

    }
}
